var SiteEDJX = {
    suffix_select: '_list',
    suffix_list_btn: '_list_btn',
    suffix_select_container: '_container',
    suffix_wait: '_list_wait',
    suffix_addbox: '_add',
    suffix_addbtn: '_add_button',
    suffix_erraddbox: '_add_error_div',
    init: function(type) {
	try {
	    SiteEDJX.list(type);
	} catch(e) {
	    setTimeOut('SiteEDJX.init(\'' + type + '\')', 750);
	}
    },
    
    add: function (type) {
	var input_box = document.getElementById(type + SiteEDJX.suffix_addbox);
	var input_button = document.getElementById(type + SiteEDJX.suffix_addbtn);
	input_button.disabled = true;
	input_box.disabled = true;
	var value = input_box.value;
	SiteEDJX.showWaiter(type);
	/*frame = document.createElement('iframe');
	frame.setAttribute('src', '/edjx/' + type + '/add/' + tool_name + '/' + value);
	frame.setAttribute('name', 'ajax_callback_x_frame');
	frame.setAttribute('style', 'display: none;');
	document.getElementsByTagName('body')[0].appendChild(frame);
	function ol_Add() {
		setTimeout('SiteEDJX.list(\'' + type + '\')', (1000));
		input_box.disabled = false;
		input_button.disabled = true;
		input_box.value = '';
	}
	frame.onload = ol_Add();*/
	//document.forms['frm_' + type + '_add'].submit();
	document.getElementById('frm_sbm_' + type).click();
	input_box.value = '';
	input_box.disabled = false;
    },
    
    addEvent: function(type) {
	var input_box = document.getElementById(type + SiteEDJX.suffix_addbox);
	var input_button = document.getElementById(type + SiteEDJX.suffix_addbtn);
	input_button.disabled = true;
	//input_box.value = '';
    },
    
    list: function(type) {
	SiteEDJX.showWaiter(type);
	frame = document.createElement('iframe');
	frame.setAttribute('src', '/edjx/' + type + '/list/' + tool_name);
	frame.setAttribute('name', 'ajax_callback_x_frame');
	frame.setAttribute('style', 'display: none;');
	document.getElementsByTagName('body')[0].appendChild(frame);
    },
    
    update: function(type, names) {
	var selObj = document.getElementById(type + SiteEDJX.suffix_select);
	selObj.options.length = 0;
	for(x in names) {
	    selObj.options[selObj.options.length] = new Option(names[x], names[x]);
	}
	SiteEDJX.showSelect(type);
    },
    
    showWaiter: function(type) {
	document.getElementById(type + SiteEDJX.suffix_wait).style.visibility = 'visible';
	document.getElementById(type + SiteEDJX.suffix_select).style.visibility = 'hidden';
	document.getElementById(type + SiteEDJX.suffix_list_btn).style.visibility = 'hidden';
	document.getElementById(type + SiteEDJX.suffix_wait).style.display = 'inline';
	document.getElementById(type + SiteEDJX.suffix_select).style.display = 'none';
	document.getElementById(type + SiteEDJX.suffix_list_btn).style.display = 'none';
    },

    showSelect: function(type) {
	document.getElementById(type + SiteEDJX.suffix_wait).style.visibility = 'hidden';
	document.getElementById(type + SiteEDJX.suffix_select).style.visibility = 'visible';
	document.getElementById(type + SiteEDJX.suffix_list_btn).style.visibility = 'visible';
	document.getElementById(type + SiteEDJX.suffix_wait).style.display = 'none';
	document.getElementById(type + SiteEDJX.suffix_select).style.display = 'inline';
	document.getElementById(type + SiteEDJX.suffix_list_btn).style.display = 'inline';
    },
    
    addChangeEvent: function(type) {
	var input_box = document.getElementById(type + SiteEDJX.suffix_addbox);
	var input_button = document.getElementById(type + SiteEDJX.suffix_addbtn);
	var submit_val = document.getElementById('frm_sbm_' + type);
	if(input_box.value != '') {
	    input_button.disabled = false;
	} else {
	    input_button.disabled = true;
	}
	submit_val.value = input_box.value;
	return true;
    },
    
    selectedEvent: function(type) {
	var selObj = document.getElementById(type + SiteEDJX.suffix_select);
	var selIndx = selObj.selectedIndex;
	if(selIndx == -1) {
	    document.getElementById(type + SiteEDJX.suffix_list_btn).disabled = true;
	} else {
	    document.getElementById(type + SiteEDJX.suffix_list_btn).disabled = false;
	}
	
    },
    
    deleteEvent: function(type) {
	SiteEDJX.showWaiter(type);
	document.getElementById(type + SiteEDJX.suffix_list_btn).disabled = true;
	var selObj = document.getElementById(type + SiteEDJX.suffix_select);
	var selIndx = selObj.selectedIndex;
	try {
	    var tagV = selObj.options[selIndx].value;
	    var tagN = selObj.options[selIndx].text;
	    /*frame = document.createElement('iframe');
	    frame.setAttribute('src', '/edjx/' + type + '/del/' + tool_name + '/' + tagV);
	    frame.setAttribute('name', 'ajax_callback_x_frame');
	    frame.setAttribute('style', 'display: none;');
	    document.getElementsByTagName('body')[0].appendChild(frame);
	    function ol_tagAdd() {
		setTimeout('SiteEDJX.list(\'' + type + '\')', (1000));
	    }
	    frame.onload = ol_tagAdd();*/
	    document.forms['frm_' + type + '_del'].submit();
	} catch(e) {
	    SiteEDJX.list(type);
	}
    },
    errorOnAdd: function(type, boolIn) {
	
    }
};